from dataclasses import dataclass

from flask import Flask, Blueprint
from injector import inject
from sqlalchemy.util import await_only

from internal.handler import AccountHandler,TicketsHandler,ProxyHandler
@inject
@dataclass
class Router:
    account_handler: AccountHandler
    ticket_handler: TicketsHandler
    proxy_handler: ProxyHandler
    def reg_router(self,app:Flask):
        bp = Blueprint('tickets',__name__,url_prefix='/api')
        bp.add_url_rule("/send_sms",methods=["POST"],view_func=self.account_handler.send_sms) #发送验证码
        bp.add_url_rule("/login",methods=["POST"],view_func=self.account_handler.login) #登录
        bp.add_url_rule("/create_tickets",methods=["POST"],view_func=self.ticket_handler.create_tickets) #保存导游
        bp.add_url_rule("/created_lvs",methods=["POST"],view_func=self.ticket_handler.created_lvs) #保存旅行社
        bp.add_url_rule("/get_tour_guide_with_list",view_func=self.ticket_handler.get_tour_guide_with_list) #导游列表
        bp.add_url_rule("/subs",view_func=self.ticket_handler.sub,methods=["POST"]) #预约
        bp.add_url_rule("/query_rservation_tickets_handler",view_func=self.ticket_handler.query_rservation_tickets_handler) #预约列表
        bp.add_url_rule("/del_tickets",methods=["POST"],view_func=self.ticket_handler.del_tickets) #删除导游以及旅行社相关
        bp.add_url_rule("/del_agency",methods=["POST"],view_func=self.ticket_handler.del_agency) #删除旅行社以及成员
        bp.add_url_rule("/del_members",methods=["POST"],view_func=self.ticket_handler.del_members) #删除成员
        bp.add_url_rule("/update_enabled",view_func=self.ticket_handler.update_enabled,methods=["POST"]) #启用/禁用
        bp.add_url_rule("/stop_agency_reservation/<string:agency_id>",methods=["POST"],view_func=self.ticket_handler.stop_agency_reservation) #停止旅行社
        bp.add_url_rule("/stop_guide_reservation/<string:bash_id>",methods=["POST"],view_func=self.ticket_handler.stop_guide_reservation) #停止导游
        bp.add_url_rule("/cancel/order_no/<string:order_no>/bash_id/<string:bash_id>/grounp_id/<string:grounp_id>",methods=["POST"],view_func=self.ticket_handler.cancel) #取消预约
        bp.add_url_rule("/re_sub_tickets/<string:agency_id>",methods=["POST"],view_func=self.ticket_handler.re_sub) #重新预约
        bp.add_url_rule("/update_play_date",methods=["POST"],view_func=self.ticket_handler.update_play_date) #修改预约日期
        bp.add_url_rule("/set_proxy",methods=["POST"],view_func=self.proxy_handler.set_proxy) #设置代理
        app.register_blueprint(bp)
